﻿﻿﻿﻿﻿﻿require.config({
  urlArgs: "version=20170407",
  paths: {
    'jquery': '/js/packages/jquery-2.14-min',
    'jquery_page':"/js/packages/jquery.twbsPagination",
    'bootstrap': '/bootstrap/js/bootstrap.min',
    'bootstrapdate': '/bootstrap/bootstrap-date/js/bootstrap-datetimepicker.min',
    
  },
  shim: {
    'bootstrap': {
      deps: ['jquery'],
      exports: 'bootstrap'
    },
  	'bootstrapdate':{
  		deps: ['jquery'],
        exports: 'bootstrap'
  	},
  	'jquery_page':{
  		deps: ['jquery'],
        exports: 'bootstrap'
  	}
  }
  
});

require(['jquery','bootstrap','bootstrapdate','jquery_page'], function ($) {
	current_depot_id = 1;
	var curr_page = 1;
	var curr_size = 20;
	//----------------------------------------------
	var data_columns = ['id','name','count','updateAt'];
	var action_columns = ['重命名','删除','相似专利检索','标引','分析绘图','生成报告','报告下载'];
	set_url('/depots/getmydepots');
	set_data_columns(data_columns);
	set_action_columns(action_columns);
	var myfunction = function() {
		$('td>div>span').click(function(){
			//var id = $(this).parent().parent().find('>ul>li>label>input').prop('checked', true);
			if($(this).text()=="重命名") {
				rename(get_curr_span_id($(this)));
			}else if($(this).text()=="删除") {
				deletede(get_curr_span_id($(this)));
			}else if($(this).text()=="标引"||$(this).text()=="重新标引") {
				start_marks(get_curr_span_id($(this)));
			}else if($(this).text()=="分析绘图") {
				start_analysis(get_curr_span_id($(this)));
			}else if($(this).text()=="生成报告") {
				start_report(get_curr_span_id($(this)));
			}else if($(this).text()=="报告下载") {
				download_report(get_curr_span_id($(this)));
			}else if($(this).text()=="相似专利检索") {
				search_similar(get_curr_span_id($(this)));
			}
		});
	};
	set_function(myfunction);
	init_page(curr_page,curr_size);
	//----------------------------------------------
	function search_similar(depote_id) {
		window.location.href="/search/similar.html?depot_id="+depote_id.split('-')[2];
	}
	function start_analysis(depote_id) {
		window.location.href="/graph/statistical.html?depot_id="+depote_id.split('-')[2];
	}
	function start_marks(depote_id) {
		window.location.href="/graph/configure.html?depot_id="+depote_id.split('-')[2];
	}
	function deletede(f_id) {
		current_depot_id = f_id.split('-')[2];
		$('#removeModal').modal('show')
	}
	function start_report(depote_id) {
		var curr_depot_id = depote_id.split('-')[2];
		window.location.href="/report/report.html?depot_id="+curr_depot_id;
	}
	function download_report(depote_id) {
		
		var curr_depot_id = depote_id.split('-')[2];
		$.get("/report/download/wordres",{"depot_id":29}, function(data){
			alert(curr_depot_id);
		});
	}
	function rename(f_id) {
		current_depot_id = f_id.split('-')[2];
		$('#renameModal').modal('show');
	}
	$("#deleteConfirm").click(function(event){
		$.post('/depots/deleteMyDepot',
		{
			id : current_depot_id,
		});

		init_page(curr_page,curr_size);
		console.log('delete '+current_depot_id)
	});
	$("#newNameConfirm").click(function(event){
		if($('#depotNewName').val()==null||$('#depotNewName').val().trim()==''){
			alert('新名称不能为空');
			return;
		}
		//console.log('new name '+current_depot_id)
		$.post('/depots/updateMyDepotName',
		{
			id : current_depot_id,
			name : $('#depotNewName').val()
		});
		init_page(curr_page,curr_size);
	});
});
